package com.tjetc.controller;
import com.github.pagehelper.PageInfo;
import com.tjetc.domain.Department;
import com.tjetc.service.DepartmentService;
import com.tjetc.service.impl.DepartmentServiceImpl;
import com.tjetc.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
* (department)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/department")
public class DepartmentController {
/**
* 服务对象
*/
@Resource
private DepartmentService departmentService;


/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping("selectOne")
public Department selectOne(@RequestParam("id") Integer id) {
return departmentService.selectByPrimaryKey(id);
}


    @GetMapping("getAll")
    public Result getAll(){
    return departmentService.selectAll();
    }
    @GetMapping("getByNameAndPage")
    public PageInfo<Department> getByNameandPage(@RequestParam("name")String name, @RequestParam("pageNum")Integer pageNum, @RequestParam("pageSize")Integer pageSize)
    {
        return departmentService.getByNameandPage(name,pageNum,pageSize);
    }
    @RequestMapping("save")
    public Result save(@RequestBody Department department)
    {
        return departmentService.save(department);
    }
    @RequestMapping("del")
    public Result del(@RequestParam("id") Integer id)
    {
        return departmentService.deleteByPrimaryKey(id)==0?Result.fail("删除失败"):Result.ok();
    }
    @GetMapping("selAllDepartment")
    public Result selAllDepartment(){
    return departmentService.selAllDepartment();
    }
}
